
<%@ include file="/html/portlet/ext/myprofile/init.jsp" %>
<%
	String profileId = request.getParameter("profileId");
	MyProfile myprofile = MyProfileUtil.findByPrimaryKey(Long.parseLong(profileId));

	User selUser = UserLocalServiceUtil.getUserById(userId);
	long p_u_i_d = (selUser != null) ? selUser.getUserId() : 0 ;
	long portrait_id = (selUser != null) ? selUser.getPortraitId(): 0;	
	
	User use = UserLocalServiceUtil.getUser(userId);
	
	Contact ct = ContactLocalServiceUtil.getContact(use.getContactId());	
	
	long addresId = 0L;
	List adder = AddressUtil.findAll();				
		for(int i=0;i<adder.size();i++){
			Address addss = (Address)adder.get(i);
			  if(addss.getClassPK()==ct.getContactId()){
				addresId = addss.getAddressId();
			  }
		}
	Address addr = AddressLocalServiceUtil.getAddress(addresId);

	long phId = 0L;
	List pho = PhoneUtil.findAll();				
		for(int i=0;i<pho.size();i++){
			Phone ph = (Phone)pho.get(i);
			  if(ph.getClassPK()==ct.getContactId()){
				phId = ph.getPhoneId();
			  }
		}	
	Phone phon = PhoneLocalServiceUtil.getPhone(phId);

	
	int prefixId = BeanParamUtil.getInteger(ct, request, "prefixId");
	
	Calendar birthday = CalendarFactoryUtil.getCalendar();
	birthday.set(Calendar.MONTH, Calendar.JANUARY);
	birthday.set(Calendar.DATE, 1);
	birthday.set(Calendar.YEAR, 1970);
	
	Calendar dateOfEstablishment = CalendarFactoryUtil.getCalendar();
	dateOfEstablishment.set(Calendar.MONTH, Calendar.JANUARY);
	dateOfEstablishment.set(Calendar.DATE, 1);
	dateOfEstablishment.set(Calendar.YEAR, 1970);

	if (ct != null) {
		birthday.setTime(ct.getBirthday());
	}
	
	PortletURL url1 = renderResponse.createActionURL();
	url1.setWindowState(WindowState.NORMAL);
	url1.setParameter("struts_action", "/ext/myprofile/add_profile");
	url1.setParameter("cmd", "EDIT");		
		
%>
<script type="text/javascript">
	function <portlet:namespace />changePortrait(newPortraitURL) {
		jQuery('#<portlet:namespace />avatar').attr('src', newPortraitURL);
		jQuery('.avatar').attr('src', newPortraitURL);

		jQuery('#<portlet:namespace />deletePortrait').val(false);
	}

	function <portlet:namespace />openEditUserPortraitWindow(editUserPortraitURL) {
		var editUserPortraitWindow = window.open(editUserPortraitURL, '<liferay-ui:message key="change" />', 'directories=no,height=400,location=no,menubar=no,resizable=yes,scrollbars=yes,status=no,toolbar=no,width=500');

		editUserPortraitWindow.focus();
	}
</script>
<portlet:actionURL  var="editEntryURL">
	<portlet:param name="struts_action" value="/ext/myprofile/add_profile" />
	<portlet:param name="<%= Constants.CMD %>" value="UPDATE" />  			
	<portlet:param name="profileId" value="<%= String.valueOf(myprofile.getProfileId()) %>" />
	<portlet:param name="addressId" value="<%= String.valueOf(addr.getAddressId()) %>" />
	<portlet:param name="phoneId" value="<%= String.valueOf(phon.getPhoneId()) %>" />				
</portlet:actionURL>


<form action="<%= editEntryURL.toString() %>" method="POST" name="<portlet:namespace />fm">

	<table width="100%"/>
		<tr class='results-header'>
			<td class='portlet-font' colspan='3' style='font-weight:bold;height:25px' nowrap>
				&nbsp;EDIT Information
			</td>			
		</tr>
		<tr class="portlet-section-body results-row alt">
		<td >My Photo:</td>

		<td >	
		<c:if test="<%= selUser != null %>">
			<portlet:renderURL windowState="<%= LiferayWindowState.POP_UP.toString() %>" var="editUserPortraitURL">
				<portlet:param name="struts_action" value="/ext/myprofile/file_book" />				
				<portlet:param name="redirect" value="<%= currentURL %>" />
				<portlet:param name="p_u_i_d" value="<%= String.valueOf(selUser.getUserId()) %>" />
				<portlet:param name="portrait_id" value="<%= String.valueOf(selUser.getPortraitId()) %>" />
			</portlet:renderURL>

			<a class="change-avatar" href="javascript: <portlet:namespace />openEditUserPortraitWindow('<%= editUserPortraitURL %>');"><img alt="<liferay-ui:message key="avatar" />" class="avatar" id="<portlet:namespace />avatar" src='<%= themeDisplay.getPathImage() %>/user_<%= selUser.isFemale() ? "female" : "male" %>_portrait?img_id=<%= selUser.getPortraitId() %>&t=<%= ImageServletTokenUtil.getToken(selUser.getPortraitId()) %>' /></a>

			<div class="portrait-icons">

				<%
				String taglibEditURL = "javascript: " + renderResponse.getNamespace() + "openEditUserPortraitWindow('" + editUserPortraitURL +"');";
				%>
				<liferay-ui:icon image="edit" message="change" url="<%= taglibEditURL %>" label="<%= true %>" />
			
			</div>
		</c:if>
		</td>
		</tr>
		<%if(!selUser.getComments().equals("student")){%>
		<tr  class="portlet-section-body results-row ">
		<td>Title:</td>
		<td>
		<select name="<portlet:namespace />prefixId">
			<option value=""></option>

			<%
			List<ListType> prefixes = ListTypeServiceUtil.getListTypes(ListTypeImpl.CONTACT_PREFIX);

			for (ListType prefix : prefixes) {
			%>

				<option <%= (prefix.getListTypeId() == prefixId) ? "selected" : "" %> value="<%= prefix.getListTypeId() %>"><liferay-ui:message key="<%= prefix.getName() %>" /></option>

			<%
			}
			%>

		</select>
		</td>		
		</tr>
		<% } %>
		<tr  class="portlet-section-body results-row ">
			<td>First Name: </td><td><liferay-ui:input-field model="<%= Contact.class %>" bean="<%= ct %>" field="firstName" />
			Last Name: <liferay-ui:input-field model="<%= Contact.class %>" bean="<%= ct %>" field="lastName" /></td>
		</tr>		
		<tr  class="portlet-section-body results-row alt">
			<td>Email Address: </td><td><liferay-ui:input-field model="<%= User.class %>" bean="<%= selUser %>" field="emailAddress" /></td>	
		</tr>		
		<tr  class="portlet-section-body results-row" >
			<td>
			<%if(selUser.getComments().equals("student")){%>
			Standard:
			<%}
			else if(selUser.getComments().equals("collStudent")){%>
			Degree:
			<%}else if(selUser.getComments().equals("")){%>			
			<%}else {%>
			Job Title:
			<%}%>			
			</td>	
		
			<td>
		<%if(!(selUser.getComments().equals(""))){

		CollStudent ctt = CollStudentUtil.fetchByMyProfileUserId(userId);
		if(ct.getJobTitle().equals("")||ct.getJobTitle().equals("Others")){%> 		 
			<liferay-ui:input-field  model="<%= CollStudent.class %>" bean="<%= ctt %>" field="others"/>
		<%}else{%>
			<liferay-ui:input-field model="<%= Contact.class %>" bean="<%= ct %>" field="jobTitle"/>
		<%}
		}%>	
		</td>		
		</tr>
		
		<tr  class="portlet-section-body results-row alt">
			<td>Birth day:</td><td><liferay-ui:input-field model="<%= Contact.class %>" bean="<%= ct %>" field="birthday" defaultValue="<%= birthday %>" />
		</td>		
		</tr>
		<tr  class="portlet-section-body results-row ">
		<td> Zip: </td><td><liferay-ui:input-field model="<%= Address.class %>" bean="<%= addr %>" field="zip" /></td>
		</tr>

		<tr  class="portlet-section-body results-row alt">
		<td>Street: </td>
		<td><liferay-ui:input-field model="<%= Address.class %>" bean="<%= addr %>" field="street1" /></td>
		</tr>

		<tr  class="portlet-section-body results-row ">
			<td>
				Phone:
			</td>
			<td>
				<liferay-ui:input-field model="<%= Phone.class %>" bean="<%= phon %>" field="number" />
			</td>	
		</tr>
		<%if(!(selUser.getComments().equals("student")||(selUser.getComments().equals("collStudent")))){%>
		<tr  class="portlet-section-body results-row alt">
			<td>
				Experience:
			</td>
			<td>
				<textarea name="experience" rows="2" cols="45"><%=myprofile.getExperience()%></textarea>
			</td>			
		</tr>
		<tr  class="portlet-section-body results-row ">
			<td>
				Employment:
			</td>
			<td>
				<textarea name="employment" rows="3" cols="45"><%=myprofile.getEmployment()%></textarea>
			</td>	
		</tr>
		<%if(!(selUser.getComments().equals("teacher")||(selUser.getComments().equals("staff")))){%>
		<tr  class="portlet-section-body results-row alt">
			<td>
				Education:
			</td>
			<td>
				<textarea name="education" rows="1" cols="45"><%=myprofile.getEducation()%></textarea>
			</td>	
		</tr>
		<%} }%>
		<%if(selUser.getComments().equals("staff")){
		Staff sf = StaffUtil.fetchByMyProfileUserId(userId);
		%>
		<tr  class="portlet-section-body results-row alt">
			<td>
				Qualification:
			</td>
			<td>
				<textarea name="qualification" rows="3" cols="45"><%=sf.getQualification()%></textarea>
			</td>	
		</tr>
		<%} %>
		<%if(selUser.getComments().equals("teacher")){
		Teacher tr = TeacherUtil.fetchByMyProfileUserId(userId);
		%>
		<tr  class="portlet-section-body results-row alt">
			<td>
				Qualification:
			</td>
			<td>
				<textarea name="qualification" rows="3" cols="45"><%=tr.getQualification()%></textarea>
			</td>	
		</tr>
		<%} %>
		<%if(selUser.getComments().equals("school")){
		School sc = SchoolUtil.fetchByMyProfileUserId(userId);	
		if (sc != null) {
		dateOfEstablishment.setTime(sc.getDateOfEstablishment());
		}		
		%>
		<tr  class="portlet-section-body results-row ">
			<td>
				Date of Establishment:
			</td>
			<td>    <liferay-ui:input-field model="<%= School.class %>" bean="<%= sc %>" field="dateOfEstablishment"  defaultValue="<%= dateOfEstablishment %>" />
				
			</td>	
		</tr>
		<tr  class="portlet-section-body results-row ">
			<td>
				Website:
			</td>
			<td>
				<input type="text" name="website" value="<%=sc.getWebsite()%>">
			</td>	
		</tr>	
		<tr  class="portlet-section-body results-row alt">
			<td>
				Number of Students:
			</td>
			<td>
				<input type="text" name="noOfStudents" value="<%=sc.getNoOfStudents()%>">
			</td>	
		</tr>	
		<tr  class="portlet-section-body results-row ">
			<td>
				Number of Teacher:
			</td>
			<td>
				<input type="text" name="noOfTeachers" value="<%=sc.getNoOfTeachers()%>">
			</td>	
		</tr>	
		<%}%>
		<%if(selUser.getComments().equals("college")){
		College cg = CollegeUtil.fetchByMyProfileUserId(userId);			
		if (cg != null) {
		dateOfEstablishment.setTime(cg.getDateOfEstablishment());
		}		
		%>
		<tr  class="portlet-section-body results-row ">
			<td>
				Date of Establishment:
			</td>
			<td>    <liferay-ui:input-field model="<%= College.class %>" bean="<%= cg %>" field="dateOfEstablishment"  defaultValue="<%= dateOfEstablishment %>" />
				
			</td>	
		</tr>
		
		<tr  class="portlet-section-body results-row ">
			<td>
				Website:
			</td>
			<td>
				<input type="text" name="website" value="<%=cg.getWebsite()%>">
			</td>	
		</tr>	
		<tr  class="portlet-section-body results-row alt">
			<td>
				Number of Students:
			</td>
			<td>
				<input type="text" name="noOfStudents" value="<%=cg.getNoOfStudents()%>">
			</td>	
		</tr>	
		<tr  class="portlet-section-body results-row ">
			<td>
				Number of Staff:
			</td>
			<td>
				<input type="text" name="noOfStaffs" value="<%=cg.getNoOfStaffs()%>">
			</td>	
		</tr>	
		<%}%>
		<%if(!(selUser.getComments().equals("school")||(selUser.getComments().equals("college")))){%>
		<tr  class="portlet-section-body results-row ">
			<td>
				Family Details:
			</td>
			<td>
				<textarea name="family" rows="3" cols="45"><%=myprofile.getFamily()%></textarea>
			</td>	
		</tr>	
		
		<tr  class="portlet-section-body results-row alt">
			<td>
				Strength:
			</td>
			<td>
				<textarea name="strength" rows="3" cols="45"><%=myprofile.getStrength()%></textarea>
			</td>	
		</tr>
		<tr  class="portlet-section-body results-row ">
			<td>
				Interests:
			</td>
			<td>
				<textarea name="interests" rows="3" cols="45"><%=myprofile.getInterests()%></textarea>
			</td>	
		</tr>
		<tr  class="portlet-section-body results-row alt">
			<td>
				Goals:
			</td>
			<td>
				<textarea name="goals" rows="3" cols="45"><%=myprofile.getGoals()%></textarea>
			</td>	
		</tr>
		<tr  class="portlet-section-body results-row">
			<td>
				weakness:
			</td>
			<td>
				<textarea name="weakness" rows="3" cols="45"><%=myprofile.getWeakness()%></textarea>
			</td>	
		</tr>

		<tr class="portlet-section-body results-row alt">
			<td>
				Hobbies:
			</td>
			<td>
				<textarea name="hobbies" rows="3" cols="45"><%=myprofile.getHobbies()%></textarea>
			</td>	
		</tr>
		</tr>

		<tr class="portlet-section-body results-row">
			<td>
				AboutMe:
			</td>
			<td>
				<textarea name="aboutMe" rows="3" cols="45"><%=myprofile.getAboutMe()%></textarea>
			</td>	
		</tr>		
		<tr class="portlet-section-body results-row alt">
			<td>
				MyFavoirate:
			</td>
			<td>
				<textarea name="myFavoirate" rows="3" cols="45"><%=myprofile.getMyFavoirate()%></textarea>
			</td>	
		</tr>
		<tr  class="portlet-section-body results-row ">
			<td>
				Languages:
			</td>
			<td>
				<textarea name="languages" rows="3" cols="45"><%=myprofile.getLanguages()%></textarea>
			</td>	
		</tr>
		<%}%>
		<table align='center'>
		<tr  class="portlet-section-body results-row alt">
			<td colspan="3">
				<input type="submit" value="Update"/>
				<input type="reset" value="Reset" />
				<input type="button"  value='Cancel' onClick='history.go(-1)'>
			</td>
		</tr>
		</table>
	</table>
</form>